import collection.TestConcurrentLinkedQueue;

import java.lang.reflect.Field;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Main {

    public static long t = 0;

    static final int NCPU = Runtime.getRuntime().availableProcessors();

    public static class ChangeT implements Runnable {
        private long to;

        public ChangeT(long to) {
            this.to = to;
        }

        @Override
        public void run() {
            while (true) {
                Main.t = to;
                Thread.yield();
            }
        }
    }

    public static class ReadT implements Runnable {
        @Override
        public void run() {
            while (true) {
                long tmp = Main.t;
                if (tmp != 111L && tmp != -999L && tmp != 333L && tmp != -444L)
                    System.out.println(tmp);
                Thread.yield();
            }
        }
    }

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException{
        System.out.println("Hello World!");

//        System.out.println(NCPU);
//        new Thread(new ChangeT(111L)).start();
//        new Thread(new ChangeT(-999L)).start();
//        new Thread(new ChangeT(333L)).start();
//        new Thread(new ChangeT(-444L)).start();
//        new Thread(new ReadT()).start();

        ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
        queue.offer("A");
//        queue.poll();

        queue.offer("B");
        queue.offer("C");
        queue.poll();
//        queue.offer("D");
//        queue.offer("E");
        String poll = queue.poll();
        System.out.println(poll);
//        queue.offer("F");
//        queue.offer("G");
     /*   作者：杨东
        链接：https://www.zhihu.com/question/67490603/answer/1077830101
        来源：知乎
        著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。*/

        /*ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
        queue.offer("A");
        Field headField = queue.getClass().getDeclaredField("head");
        headField.setAccessible(true);
        Object headNode = headField.get(queue);

        Field headNodeItemField = headNode.getClass().getDeclaredField("item");
        headNodeItemField.setAccessible(true);
        Object headNodeItemValue = headNodeItemField.get(headNode);

        Field nextField = headNode.getClass().getDeclaredField("next");
        nextField.setAccessible(true);
        Object nextNode = nextField.get(headNode);

        Field nextNodeItemField = nextNode.getClass().getDeclaredField("item");
        nextNodeItemField.setAccessible(true);
        Object nextNodeItemValue = nextNodeItemField.get(nextNode);

        System.out.println("head node: " + headNode);
        System.out.println("head node item value: " + headNodeItemValue);
        System.out.println("next node item value: " + nextNodeItemValue);*/

    }
}


